home *** CD-ROM | disk | FTP | other *** search
/ Chip 2011 November / CHIP_2011_11.iso / Programy / Inne / Gry / Carnage_Contest / scripts / CC Original / weapons / Super Shotgun.lua < prev    next >
Text File  |  2010-08-31  |  6KB  |  165 lines

  1. --------------------------------------------------------------------------------
  2. -- Weapon Super Shotgun + Projectile Bullet
  3. -- Original Carnage Contest Weapon
  4. -- Script by DC, October 2009, www.UnrealSoftware.de
  5. --------------------------------------------------------------------------------
  6.  
  7. -- Setup Tables
  8. if cc==nil then cc={} end
  9. cc.supershotgun={}
  10. cc.supershotgun.bullet={}
  11.  
  12. -- Load & Prepare Ressources
  13. cc.supershotgun.gfx_wpn=loadgfx("weapons/supershotgun.bmp")                -- Weapon Image
  14. setmidhandle(cc.supershotgun.gfx_wpn)
  15. cc.supershotgun.gfx_pro=loadgfx("weapons/shot.bmp")                        -- Projectile Image
  16. setmidhandle(cc.supershotgun.gfx_pro)
  17. cc.supershotgun.sfx_attack=loadsfx("shotgun.wav")                        -- Attack Sound
  18.  
  19. --------------------------------------------------------------------------------
  20. -- Weapon: Super Shotgun
  21. --------------------------------------------------------------------------------
  22.  
  23. cc.supershotgun.id=addweapon("cc.supershotgun","Super Shotgun",cc.supershotgun.gfx_wpn,0)    -- Add Weapon (0 uses)
  24. cc.supershotgun.ammo=3                                                    -- 3 Shots (each 7 bullets)
  25.  
  26. function cc.supershotgun.draw()                                            -- Draw
  27.     setblend(blend_alpha)
  28.     setalpha(1)
  29.     setcolor(255,255,255)
  30.     drawinhand(cc.supershotgun.gfx_wpn,6,0)
  31.     -- HUD ammobar
  32.     if cc.supershotgun.ammo-weapon_shots>0 then
  33.         hudammobar(cc.supershotgun.ammo-weapon_shots,cc.supershotgun.ammo)
  34.     end
  35.     -- HUD Crosshair
  36.     if cc.supershotgun.ammo-weapon_shots>0 then
  37.         hudcrosshair(7,3)
  38.     end
  39. end
  40.  
  41. function cc.supershotgun.attack(attack)                                    -- Attack
  42.     -- Decrement timer
  43.     if weapon_timer>0 then
  44.         weapon_timer=weapon_timer-1
  45.     end
  46.     -- Attack
  47.     if weapon_shots<cc.supershotgun.ammo and weapon_timer<=0 and attack==1 then
  48.         -- No more weapon switching!
  49.         useweapon(0)
  50.         -- Reset Timer
  51.         weapon_timer=20
  52.         -- Attack
  53.         playsound(cc.supershotgun.sfx_attack)
  54.         weapon_shots=weapon_shots+1
  55.         for i=-3,3,1 do
  56.             id=createprojectile(cc.supershotgun.bullet.id)
  57.             projectiles[id]={}
  58.             rot=getplayerrotation(0)+(i*3)
  59.             -- Ignore collision with current player at beginning
  60.             projectiles[id].ignore=playercurrent()
  61.             -- Set initial position of projectile
  62.             projectiles[id].x=getplayerx(0)+(7*getplayerdirection(0))-math.sin(math.rad(rot))*5.0
  63.             projectiles[id].y=getplayery(0)+3+math.cos(math.rad(rot))*5.0
  64.             -- Set speed of projectile
  65.             projectiles[id].sx=math.sin(math.rad(rot))*15.0
  66.             projectiles[id].sy=-math.cos(math.rad(rot))*15.0
  67.             -- Initial movement
  68.             projectiles[id].x=projectiles[id].x-projectiles[id].sx*1.5
  69.             projectiles[id].y=projectiles[id].y-projectiles[id].sy*1.5
  70.             for i=1,3,1 do
  71.                 if cc.supershotgun.bullet.move(id)==1 then
  72.                     break
  73.                 end
  74.             end
  75.         end
  76.         -- Effects
  77.         recoil(7)
  78.         particle(p_muzzle,getplayerx(0)+(getplayerdirection(0)*7)+math.sin(math.rad(getplayerrotation(0)))*16,getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*16)
  79.         particle(p_smoke,getplayerx(0)+(getplayerdirection(0)*7)+math.sin(math.rad(getplayerrotation(0)))*16,getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*16)
  80.         particlespeed(-0.2+math.random()*0.4+getwind()*10.0,-1.0+math.random()*0.6)
  81.         particlefadealpha(0.005)
  82.         -- End Turn
  83.         if (weapon_shots>=cc.supershotgun.ammo) then
  84.             endturn()
  85.         end
  86.     end
  87. end
  88.  
  89. --------------------------------------------------------------------------------
  90. -- Projectile: Bullet
  91. --------------------------------------------------------------------------------
  92.  
  93. cc.supershotgun.bullet.id=addprojectile("cc.supershotgun.bullet")        -- Add Projectile
  94.  
  95. function cc.supershotgun.bullet.draw(id)                                -- Draw
  96.     -- Setup draw mode
  97.     setblend(blend_light)
  98.     setalpha(1)
  99.     setcolor(255,125,0)
  100.     setscale(1,1)
  101.     -- Calculate projectile rotation
  102.     setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
  103.     -- Draw projectile
  104.     drawimage(cc.supershotgun.gfx_pro,projectiles[id].x,projectiles[id].y)
  105.     -- Draw Arrow if out of Screen
  106.     outofscreenarrow(projectiles[id].x,projectiles[id].y)
  107. end
  108.  
  109. function cc.supershotgun.bullet.update(id)                                -- Update
  110.     -- Wind + Gravity influence on speed
  111.     projectiles[id].sx=projectiles[id].sx+getwind()*0.02
  112.     projectiles[id].sy=projectiles[id].sy+getgravity()*0.75
  113.     -- Move
  114.     cc.supershotgun.bullet.move(id)
  115. end
  116.  
  117. function cc.supershotgun.bullet.move(id)
  118.     rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
  119.     -- Move (in substep loop for optimal collision precision)
  120.     msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
  121.     msubx=projectiles[id].sx/msubt
  122.     msuby=projectiles[id].sy/msubt
  123.     for i=1,msubt,1 do
  124.         projectiles[id].x=projectiles[id].x+msubx
  125.         projectiles[id].y=projectiles[id].y+msuby        
  126.         -- Collision
  127.         if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*20,projectiles[id].y-math.cos(math.rad(rot))*20)==1 then
  128.             if terraincollision()==1 or objectcollision()>0 or playercollision()~=projectiles[id].ignore then
  129.                 -- Cause Player damage
  130.                 if playercollision()~=0 and playercollision()~=projectiles[id].ignore then
  131.                     playerpush(playercollision(),projectiles[id].sx/10.0,projectiles[id].sy/10.0)
  132.                     playerdamage(playercollision(),5)
  133.                     blood(projectiles[id].x+math.sin(math.rad(rot))*20,projectiles[id].y-math.cos(math.rad(rot))*20)
  134.                 elseif objectcollision()>0 then
  135.                     objectdamage(objectcollision(),5)
  136.                 end
  137.                 -- Destroy terrain
  138.                 terrainexplosion(projectiles[id].x+math.sin(math.rad(rot))*20,projectiles[id].y-math.cos(math.rad(rot))*20,12,0)
  139.                 -- Effects
  140.                 playsound(sfx_ricochet1)
  141.                 particle(p_smoke,projectiles[id].x+math.sin(math.rad(rot))*21,projectiles[id].y-math.cos(math.rad(rot))*21)
  142.                 particlefadealpha(0.004)
  143.                 particle(p_muzzle,projectiles[id].x+math.sin(math.rad(rot))*21,projectiles[id].y-math.cos(math.rad(rot))*21)
  144.                 -- Free projectile
  145.                 freeprojectile(id)
  146.                 return 1
  147.             end
  148.         else
  149.             projectiles[id].ignore=0
  150.         end
  151.         -- Water
  152.         if (projectiles[id].y)>getwatery()+5 then
  153.             -- Effects
  154.             particle(p_waterhit,projectiles[id].x,projectiles[id].y)
  155.             if math.random(1,2)==1 then
  156.                 playsound(sfx_hitwater2)
  157.             else
  158.                 playsound(sfx_hitwater3)
  159.             end
  160.             -- Free projectile
  161.             freeprojectile(id)
  162.             return 1
  163.         end
  164.     end
  165. end